package biz.innovasoft.nodb.interceptors;

import java.lang.reflect.Method;
import java.util.List;

import net.sf.cglib.proxy.InvocationHandler;

import org.prevayler.Prevayler;

import biz.innovasoft.nodb.query.Tuple;
import biz.innovasoft.nodb.transaction.UpdateUpdateableListTransaction;

public class UpdateableListInterceptor implements InvocationHandler {

	private Prevayler prevayler;
	private List<Tuple> tuples;
	
	public UpdateableListInterceptor (Prevayler prevayler, List<Tuple> tuples) {
		this.prevayler = prevayler;
		this.tuples = tuples;
	}
	
	
	@Override
	public Object invoke(Object obj, Method method, Object[] args)
			throws Throwable {
		if (method.getName().equals ("commit")) {
			prevayler.execute(new UpdateUpdateableListTransaction (tuples));
		}
		return method.invoke(tuples, args);
	}

}
